package com.briup.day29;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ThinkBook
 */
public class TestObjectServer {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        // 创建服务器对象
        ServerSocket serverSocket = new ServerSocket(8888);
        System.out.println("服务器成功启动，serverSocket" + serverSocket);
        // 获取客户端连接
        Socket socket = serverSocket.accept();
        // 拿到输入流
        ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
        // 读取数据
        Object o = ois.readObject();
        List<Student> students = new ArrayList<>();
        if (o instanceof List) {
            students = (List<Student>) o;
        }
        // 遍历student集合
        for (Student s : students) {
            System.out.println(s);
        }
        // 关闭资源
        ois.close();
        socket.close();
        serverSocket.close();
    }
}
